package cn.boy.adapter;

import java.util.List;
import cn.boy.domain.Dormitory;
import cn.boy.home.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HistoryAdapter extends BaseAdapter {
	
	Context context;
	List<Dormitory> dorms;
	
	

	public List<Dormitory> getDorms() {
		return dorms;
	}

	public void setDorms(List<Dormitory> dorms) {
		this.dorms = dorms;
	}

	public HistoryAdapter(Context context, List<Dormitory> dorms) {
		super();
		this.context = context;
		this.dorms = dorms;
	}

	public int getCount() {
		return dorms.size();
	}

	public Object getItem(int position) {
		return dorms.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View row=convertView;

		ViewHolder holder;

		if (row==null) {
			
			row = LayoutInflater.from(context).inflate(R.layout.history_list_item, null);

			holder = new ViewHolder();
			holder.txtName = (TextView)row.findViewById(R.id.tv_list_name);
			holder.txtMark = (TextView)row.findViewById(R.id.tv_list_mark);
			holder.txtDate = (TextView)row.findViewById(R.id.tv_history_date);
			row.setTag(holder);
		}
		else{
			holder = (ViewHolder) row.getTag();
		}
		
		holder.txtName.setText(dorms.get(position).getName());
		holder.txtMark.setText(dorms.get(position).getMark());
		holder.txtDate.setText(dorms.get(position).getDate());
		return row;
	}
	
	static class ViewHolder {
		TextView txtName;
		TextView txtMark;
		TextView txtDate;
	}

}
